package cn.demomaster.quickui_sample.ui.fragment.helper;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.demomaster.quickcompat.widget.button.QuickButton;

import cn.demomaster.quicklogger.QdLog;
import cn.demomaster.quickrouter.fragment.QuickFragment;
import cn.demomaster.quickui.annotation.ActivityPager;
import cn.demomaster.quickui.annotation.ResType;
import com.demomaster.quickcompat.widget.toast.QdToast;
import cn.demomaster.quickui_sample.R;
import cn.demomaster.quickui_sample.util.NetPrinter;

/**
 * Squirrel桓
 * 2021/6/21
 */

@ActivityPager(name = "打印机", preViewClass = TextView.class, resType = ResType.Custome)
public class PrinterFragment extends QuickFragment {

    //Components
    QuickButton btn_print;

    @NonNull
    @Override
    public View onGenerateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View mView = inflater.inflate(R.layout.fragment_layout_printer, null);
        return mView;
    }

    private NetPrinter printer;
    public void initView(View rootView) {
        btn_print = findViewById(R.id.btn_print);
        //getActionBarTool().setHeaderBackgroundColor(Color.RED);
        btn_print.setOnClickListener(v -> {
            QdToast.show("printer");

            Thread thread =  new Thread(new Runnable() {
                @Override
                public void run() {
                    printer = new NetPrinter();
                    printer.Open("172.16.11.183", 9100);
                    QdLog.e("printer.IFOpen="+printer.IFOpen);
                    if(printer.IFOpen){

                    }
                }
            });
            thread.start();
        });
    }

}